home *** CD-ROM | disk | FTP | other *** search
- #include <Values.h>
-
- #define kBaseResID 128
- #define kMoveToFront (WindowPtr)-1L
- #define kSleep MAXLONG
-
- #define kScrollBarAdjust (16-1)
- #define kLeaveWhereItIs false
- #define kNormalUpdates true
-
- #define kMinWindowHeight 50
- #define kMinWindowWidth 80
-
-
- /*************/
- /* Globals */
- /*************/
-
- Boolean gDone;
-
-
- /***************/
- /* Functions */
- /***************/
-
- void ToolBoxInit( void );
- void WindowInit( void );
- void EventLoop( void );
- void DoEvent( EventRecord *eventPtr );
- void HandleMouseDown( EventRecord *eventPtr );
- void DoUpdate( EventRecord *eventPtr );
- void DoPicture( WindowPtr window, PicHandle picture );
- void DoActivate( WindowPtr window, Boolean becomingActive );
- void DoSuspendResume( Boolean resuming );
- void CenterPict( PicHandle picture, Rect *srcRectPtr,
- Rect *destRectPtr );
-
-
- /******************************** main *********/
-
- void main( void )
- {
- ToolBoxInit();
- WindowInit();
-
- EventLoop();
- }
-
-
- /*********************************** ToolBoxInit */
-
- void ToolBoxInit( void )
- {
- InitGraf( &thePort );
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs( nil );
- InitCursor();
- }
-
-
- /******************************** WindowInit *********/
-
- void WindowInit( void )
- {
- WindowPtr window;
-
- window = GetNewWindow( kBaseResID, nil, kMoveToFront );
-
- if ( window == nil )
- {
- SysBeep( 10 ); /* Couldn't load the WIND resource!!! */
- ExitToShell();
- }
-
- ShowWindow( window );
- SetPort( window );
- }
-
-
- /******************************** EventLoop *********/
-
- void EventLoop( void )
- {
- EventRecord event;
-
- gDone = false;
- while ( gDone == false )
- {
- if ( WaitNextEvent( everyEvent, &event, kSleep, nil ) )
- DoEvent( &event );
- }
- }
-
-
- /************************************* DoEvent */
-
- void DoEvent( EventRecord *eventPtr )
- {
- Boolean becomingActive, resuming;
-
- switch ( eventPtr->what )
- {
- case mouseDown:
- HandleMouseDown( eventPtr );
- break;
- case updateEvt:
- DoUpdate( eventPtr );
- break;
- case activateEvt:
- becomingActive = ( (eventPtr->modifiers & activeFlag)
- == activeFlag );
- DoActivate( (WindowPtr)eventPtr->message, becomingActive );
- break;
- case osEvt:
- resuming = ( eventPtr->message & suspendResumeMessage )
- == resumeFlag;
- DoSuspendResume( resuming );
- break;
- }
- }
-
-
- /************************************* HandleMouseDown */
-
- void HandleMouseDown( EventRecord *eventPtr )
- {
- WindowPtr window;
- short thePart;
- GrafPtr oldPort;
- long windSize;
- Rect growRect;
-
- thePart = FindWindow( eventPtr->where, &window );
-
- switch ( thePart )
- {
- case inSysWindow :
- SystemClick( eventPtr, window );
- break;
- case inContent:
- SelectWindow( window );
- break;
- case inDrag :
- DragWindow( window, eventPtr->where, &screenBits.bounds );
- break;
- case inGoAway :
- if ( TrackGoAway( window, eventPtr->where ) )
- gDone = true;
- break;
- case inGrow:
- growRect.top = kMinWindowHeight;
- growRect.left = kMinWindowWidth;
- growRect.bottom = MAXSHORT;
- growRect.right = MAXSHORT;
-
- windSize = GrowWindow( window, eventPtr->where, &growRect );
- if ( windSize != 0 )
- {
- GetPort( &oldPort );
- SetPort( window );
- EraseRect( &window->portRect );
- SizeWindow( window, LoWord( windSize ),
- HiWord( windSize ), kNormalUpdates );
- InvalRect( &window->portRect );
- SetPort( oldPort );
- }
- break;
- case inZoomIn:
- case inZoomOut:
- if ( TrackBox( window, eventPtr->where, thePart ) )
- {
- GetPort( &oldPort );
- SetPort( window );
- EraseRect( &window->portRect );
- ZoomWindow( window, thePart, kLeaveWhereItIs );
- InvalRect( &window->portRect );
- SetPort( oldPort );
- }
- break;
- }
- }
-
-
- /************************************* DoUpdate */
-
- void DoUpdate( EventRecord *eventPtr )
- {
- short pictureID;
- PicHandle picture;
- WindowPtr window;
-
- window = (WindowPtr)eventPtr->message;
-
- BeginUpdate( window );
-
- picture = GetPicture( kBaseResID );
-
- if ( picture == nil )
- {
- SysBeep( 10 ); /* Couldn't load the PICT resource!!! */
- ExitToShell();
- }
-
- DoPicture( window, picture );
-
- EndUpdate( window );
- }
-
-
- /******************************** DoPicture *********/
-
- void DoPicture( WindowPtr window, PicHandle picture )
- {
- Rect drawingClipRect, destRect;
- RgnHandle tempRgn;
-
- SetPort( window );
-
- EraseRect( &window->portRect );
-
- tempRgn = NewRgn();
- GetClip( tempRgn );
-
- drawingClipRect = window->portRect;
- drawingClipRect.right -= kScrollBarAdjust;
- drawingClipRect.bottom -= kScrollBarAdjust;
-
- ClipRect( &drawingClipRect );
-
- CenterPict( picture, &drawingClipRect, &destRect );
- DrawPicture( picture, &destRect );
-
- SetClip( tempRgn );
- DisposeRgn( tempRgn );
-
- DrawGrowIcon( window );
- }
-
-
- /************************************* DoActivate */
-
- void DoActivate( WindowPtr window, Boolean becomingActive )
- {
- DrawGrowIcon( window );
- }
-
-
- /************************************* DoSuspendResume */
-
- void DoSuspendResume( Boolean resuming )
- {
- WindowPtr window;
-
- window = FrontWindow();
-
- DrawGrowIcon( window );
- }
-
-
- /****************** CenterPict ********************/
-
- void CenterPict( PicHandle picture, Rect *srcRectPtr,
- Rect *destRectPtr )
- {
- Rect pictRect;
-
- pictRect = (**( picture )).picFrame;
-
- OffsetRect( &pictRect, srcRectPtr->left - pictRect.left,
- srcRectPtr->top - pictRect.top);
- OffsetRect( &pictRect,(srcRectPtr->right - pictRect.right)/2,
- (srcRectPtr->bottom - pictRect.bottom)/2);
-
- *destRectPtr = pictRect;
- }
-